package org.zjvis.datascience.common.widget.vo;

import cn.weiguangfu.swagger2.plus.annotation.ApiRequestInclude;
import com.alibaba.fastjson.JSONObject;
import lombok.Data;
import org.zjvis.datascience.common.util.DozerUtil;
import org.zjvis.datascience.common.validator.NotNullNumber;
import org.zjvis.datascience.common.widget.dto.WidgetDTO;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.time.LocalDateTime;
import java.util.List;

/**
 * @description 用于可视化系统构建 可用图表控件的结果类VO
 * @date 2021-12-01
 */
@Data
public class WidgetVO {

    @ApiRequestInclude(groups = {WidgetVO.ID.class})
    @NotNullNumber(message = "widgetId cannot be null", groups = {WidgetVO.ID.class})
    private Long id;

    private Long tid;

    @ApiRequestInclude(groups = {WidgetVO.TID.class})
    private String tids;

    private String type;

    private String name;

    @NotNull(message = "data cannot be null", groups = WidgetVO.VO.class)
    @NotEmpty(message = "data cannot be empty", groups = WidgetVO.VO.class)
    private JSONObject data;

    private String publishName;

    private JSONObject publishData;

    private LocalDateTime publishTime;

    @ApiRequestInclude(groups = {WidgetVO.ID.class, WidgetVO.IDs.class, WidgetVO.TID.class})
    private Long projectId;//用于权限校验,前端传入

    private String status;

    private Long dashboardId;

    @ApiRequestInclude(groups = {WidgetVO.IDs.class})
    private List<Long> widgetIds;

    @ApiRequestInclude(groups = {WidgetVO.PUBLISH.class})
    private String publishNo;

    public WidgetDTO toWidget() {
        WidgetDTO widget = DozerUtil.mapper(this, WidgetDTO.class);
        if (data != null) {
            widget.setDataJson(data.toJSONString());
        }
        if (publishData != null) {
            widget.setPublishDataJson(publishData.toJSONString());
        }
        return widget;
    }

    public interface ID{
        //widgetId + projectId(校验位)
    }

    public interface IDs{
        //widgetId + projectId(校验位)
    }

    public interface TID{
        //taskId + projectId(校验位)
    }

    public interface VO{

    }

    public interface PUBLISH{

    }


}
